package com.jackrain.nea.fc.dl.mapper;


import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * wms出入库回写
 * Mapper
 *
 * @author zhang.zz
 * @create 2018/12/07
 */
@Mapper
public interface WmsBackWriteBillNoMapper {



    @Update("UPDATE DL_B_TRAN SET WMS_IN='Y' WHERE BILL_NO IN ( #{ids} ) ")
    int updattraninwmsState(
            @Param("ids") String ids
    );

    @Update("UPDATE DL_B_TRAN SET WMS_OUT='Y' WHERE BILL_NO IN ( #{ids} ) ")
    int updattranoutwmsState(
            @Param("ids") String ids
    );

    @UpdateProvider(type = WmsBackWriteBillNoMapper.ViewWmsSql.class, method = "updatetranboxwmsState")
    int updatetranboxwmsState(@Param("id") Object[] id);

    @SelectProvider(type = WmsBackWriteBillNoMapper.ViewWmsSql.class, method = "findIdListByBillNo")
    List<Long> findIdListByBillNo(@Param("id") Object[] billnos);

        @UpdateProvider(type = WmsBackWriteBillNoMapper.ViewWmsSql.class, method = "updatetranboxwmsState1")
    int updatetranboxwmsState1(@Param("id") Object[] id);

    @Update("UPDATE DL_B_PUR_RET SET WMS_OUT='Y' WHERE BILL_NO IN ( #{ids} ) ")
    int updatpurretwmsState(
            @Param("ids") String ids
    );
    @Update("UPDATE DL_B_PUR_IN SET WMS_IN='Y' WHERE BILL_NO IN ( #{ids} ) ")
    int updatpurinwmsState(
            @Param("ids") String ids
    );


    @Update("UPDATE DL_B_PUR_ORDER SET WMS_IN='Y' WHERE BILL_NO IN ( #{ids} ) ")
    int updatorderwmsState(
            @Param("ids") String ids
    );

//    @Update("UPDATE DL_B_TRAN SET WMS_OUT='Y' WHERE BILL_NO IN ( #{ids} ) ")
//    int updatwmssubmitState(
//            @Param("ids") Object[] ids
//    );

    @Update("UPDATE DL_B_TRAN SET WMS_IN='Y' WHERE BILL_NO IN ( #{ids} ) ")
    int updatwmssendState(
            @Param("ids") String ids
    );
    @UpdateProvider(type = WmsBackWriteBillNoMapper.ViewWmsSql.class, method = "updatewmssubmit")
    int updatwmssubmitState(@Param("id") Object[] id);

    class ViewWmsSql {
        public String updatewmssubmit(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    UPDATE(" DL_B_TRAN ");
                    SET(" WMS_OUT='Y' ");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" BILL_NO IN (" + sb.toString() + ") ");
                }
            }.toString();
        }
        public String findIdListByBillNo(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("ID AS ID ");
                    FROM("DL_B_TRAN");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" BILL_NO IN (" + sb.toString() + ") ");
                }
            }.toString();
        }
        public String updatetranboxwmsState(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    UPDATE(" DL_B_TRAN ");
                    SET(" WMS_OUT='Y' ");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" BILL_NO IN (" + sb.toString() + ") ");
                }
            }.toString();
        }
        public String updatetranboxwmsState1(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    UPDATE(" DL_B_TRAN ");
                    SET(" WMS_OUT='Y' ");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE(" TRAN_B_BILL_BOX_ID IN (" + sb.toString() + ") ");
                }
            }.toString();
        }
    }
}
